package com.neusoft.cebc.bv.function.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.cebc.bv.ao.BrandAo;
import com.neusoft.cebc.bv.dao.BvBrandDao;
import com.neusoft.cebc.bv.entity.BvBrand;
import com.neusoft.cebc.bv.function.BvBrandFunction;

import static com.neusoft.cebc.util.AssertThrowUtil.*;
import static com.neusoft.cebc.util.ThisSystemUtil.*;

import java.util.Date;

@Service
public class BvBrandFunctionImpl implements BvBrandFunction{
	@Autowired
	private BvBrandDao brandDao;
	
	@Override
	public BvBrand addBrand(BrandAo ao) throws Exception {
		//1.验证参数
		String nameEN = $("英文名",ao.getNameEN());
		int isTrue = brandDao.exist("name_en",nameEN);
		if(isTrue > 0) {
			assertTrue("英文名",false);
		}
		String nameCN = $("中文名",ao.getNameCN());
		isTrue = brandDao.exist("name_cn",nameCN);
		if(isTrue > 0) {
			assertTrue("中文名",false);
		}
		String GMCReportType = $("证书类型",ao.getGMCReportType());
		String GMCReportURL = $("证书地址",ao.getGMCReportURL());
		String introduction = ao.getIntroduction();
		//2.执行业务方法
		BvBrand brand = new BvBrand();
		brand.setId(getUUID());
		Date createTime = new Date();
		brand.setCreateTime(createTime);
		brand.setNameEn(nameEN);
		brand.setNameCn(nameCN);
		brand.setGmcReportType(GMCReportType);
		brand.setGmcReportUrl(GMCReportURL);
		brand.setRemark(introduction);
		brandDao.insert(brand);
		//3.组装返回业务结果
		
		return brand;
	}

}
